package com.dlut.txy.designpattern.chainofresponsibility.approve1;

import com.dlut.txy.designpattern.chainofresponsibility.approve1.entity.AskForLeaveRequest;

/**
 * 请假审批
 * 参考 https://blog.csdn.net/CharlesYooSky/article/details/128779448 示例1
 * 做了一点优化，next逻辑放到父类里，不在各个子类中重复实现
 */
public abstract class AskForLeaveApproveHandler {
    private AskForLeaveApproveHandler nextHandler;
    public abstract int getApproveMax();
    public void handleRequest(AskForLeaveRequest request) {
        if(request.getAskForLeaveDays()<=getApproveMax()) {
            customHandle(request);
        } else {
            if(getNext()==null) {
                System.out.println("驳回");
            }else {
                getNext().handleRequest(request);
            }
        }
    }

    protected abstract void customHandle(AskForLeaveRequest request);

    public void setNext(AskForLeaveApproveHandler next) {
        this.nextHandler = next;
    }
    protected AskForLeaveApproveHandler getNext() {
        return nextHandler;
    };
}
